﻿namespace DotNetUtility.Parser
{
    using System.Text.RegularExpressions;
    using DotNetUtility.ExtensionMethods;

    public static class RegularExpressionParser
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsAlphaNumeric(string itemToCheck)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.AlphaNumeric
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <param name="lengthToMatch"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsAlphaNumericAndSizeLimitOf(string itemToCheck, int lengthToMatch)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.AlphaNumericWithLength.FormatWith(lengthToMatch.ToString().PrefixAndPostfixCurlyBrackets())
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <param name="numberOfDigitsToMatch"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsAlphaNumericWithNoOfDigitsAtEnd(string itemToCheck, int numberOfDigitsToMatch)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.AlphaNumericWithNoOfDigitsAtEnd.FormatWith(numberOfDigitsToMatch.ToString().PrefixAndPostfixCurlyBrackets())
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <param name="numberOfDigitsToMatch"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsAlphaNumericWithNoOfDigitsAtFront(string itemToCheck, int numberOfDigitsToMatch)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.AlphaNumericWithNoOfDigitsAtFront.FormatWith(numberOfDigitsToMatch.ToString().PrefixAndPostfixCurlyBrackets())
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <param name="numberOfDigitsToMatch"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsNumericWithNoOfDigits(string itemToCheck, int numberOfDigitsToMatch)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.NumericWithNoOfDigits.FormatWith(numberOfDigitsToMatch.ToString().PrefixAndPostfixCurlyBrackets())
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <param name="startOfRange"></param>
        /// <param name="endOfRange"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsNumericInRangeOf(string itemToCheck, int startOfRange, int endOfRange)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.NumericWithNoOfDigits.FormatWith(string.Concat(startOfRange, ",", endOfRange).PrefixAndPostfixCurlyBrackets())
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsAlphabetic(string itemToCheck)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.Alphabetic
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <param name="startOfRange"></param>
        /// <param name="endOfRange"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsAlphabeticInRangeOf(string itemToCheck, int startOfRange, int endOfRange)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.AlphabeticInRange.FormatWith(string.Concat(startOfRange, ",", endOfRange).PrefixAndPostfixCurlyBrackets())
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsAlphabeticInUppercase(string itemToCheck)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.AlphabeticInUppercase
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsAlphabeticInLowercase(string itemToCheck)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.AlphabeticInLowercase
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsValidEmailAddress(string itemToCheck)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.EmailAddress
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsArticle(string itemToCheck)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.Article
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsVowel(string itemToCheck)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.Vowel
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <param name="alphabetSet"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsFirstLetterIsInAlphabetSet(string itemToCheck, string alphabetSet)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.FirstLetterIsInAlphabetSet.FormatWith(alphabetSet).AppendNoOfTimes(".", itemToCheck.Length - 1)
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <param name="alphabetSet"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        public static bool IsFirstLetterIsNotInAlphabetSet(string itemToCheck, string alphabetSet)
        {
            return Execute(
                itemToCheck,
                ExpressionPattern.FirstLetterIsNotInAlphabetSet.FormatWith(alphabetSet).AppendNoOfTimes(".", itemToCheck.Length - 1)
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemToCheck"></param>
        /// <param name="pattern"></param>
        /// <returns></returns>
        /// Contributed by Mohammad Rahman
        private static bool Execute(string itemToCheck, string pattern)
        {
            return Regex.IsMatch(itemToCheck, pattern);
        }
    }
}
